<?php
/* 
 *采购询价 详情处理
 */
class Ask_supplier_detailAction extends CommonAction {
    public function _filter(&$map) {
        $key = trim($_REQUEST['keywords']);
        if(!empty($key)) {
            $map['Supplier.name'] = array('like',"%".$key."%");
            $map['Product.name'] = array('like',"%".$key."%"); //产品名称
            $map['_logic'] = "or";
        }
    }

    public function search(){
        $this->index('Ask_supplier_detailView');
    }

    public function _before_add(){
        if(empty($_REQUEST['asid']))
            $this->error("请选择询价单");
    }

    public function insert(){
        //将供应商的默认联系人置入报价中
        $_POST['contact_id'] = getModelName( $_POST['supplier_id'] ,'Supplier','contact_id');
    	if(empty($_POST['supplier_id']))
            $this->error("请选择供应商");

        $asid = $_POST['ask_supplier_id']; 

    	//将询价主表状态置为询价中。如果是待确认状态
        if($status = M('Ask_supplier')->where('id = '.$asid)->getField('status') == 0 ){
            M('Ask_supplier')->where('id = '.$asid)->setField('status',1);
            $inquiry_id = M('Ask_supplier')->where('id = '.$asid)->getField('inquiry_id');
            if($inquiry_id) //客户询单联动
                M('Inquiry')->where('id = '.$inquiry_id)->setField('status',1);
        }
    	   
    	parent::insert();
    }

}
?>
